package com.yunhe.authority.repository.paymentInfo;

import com.yunhe.authority.domain.company.PropertyCost;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * @ClassName: PropertyCostRepository
 * @Description:
 * @author: GongDaCheng
 * @Date: 15:51 2021/7/16
 */
@Repository
public interface PropertyCostRepository extends Neo4jRepository<PropertyCost, Long> {

    /**
     * @Description 物业费用信息与企业绑定
     * @Param Long companyId, Long id
     * @Return
     * @Date 2021/7/16 15:54
     */
    @Query("match (c:Company),(pc:PropertyCost) where ID(c)={companyId} and ID(pc)={id} create (c)-[r:HAS_PROPERTY_COST]->(pc)")
    void bindCompany(@Param("companyId") Long companyId, @Param("id") Long id);

    /**
     * @Description 根据企业id查询企业缴费物业费用信息
     * @Param Long companyId
     * @Return PropertyCost
     * @Date 2021/7/16 16:15
     */
    @Query("match (c:Company)-[r:HAS_PROPERTY_COST]->(pc:PropertyCost) where ID(c)={companyId} return pc")
    PropertyCost getByCompanyId( @Param("companyId") Long companyId);

    /**
     * @Description 根据企业id解绑并删除企业缴费物业费用信息
     * @Param Long companyId
     * @Return
     * @Date 2021/8/17 17:42
     */
    @Query("match (c:Company)-[r:HAS_PROPERTY_COST]->(pc:PropertyCost) where ID(c)={companyId} delete r, pc")
    void unbindAndDelete(@Param("companyId") Long companyId);
}
